const db = wx.cloud.database()
const collectionName = 'collect'
let $ = db.command.aggregate
export default {
  async add(data) {
    let res = await db.collection(collectionName).add({
      data: data
    })
    return res
  },

  async delete({
    activeId,
    openid
  }) {
    var res = await db.collection(collectionName).where({
      activeId,
      openid
    }).remove()
    return res
  },

  async getList({
    pageNum,
    pageSize,
    activeId,
    openid
  }) {
    let skip = (pageNum - 1) * pageSize
    let matchObj = {}
    if (activeId) {
      matchObj.activeId = activeId
    }
    if (openid) {
      matchObj.openid = openid
    }
    let res = await db.collection(collectionName).aggregate()
      .match(matchObj)
      .skip(skip)
      .limit(pageSize)
      .end()
    return res.list
  },
  async getCollectActiveList(params) {

    params.methodName = 'getCollectActiveList'
    let res = await wx.cloud.callFunction({
      name: 'activeApi',
      data: params
    })
    
    return res.result

   
  }

}